package monitor.test

import akka.actor.{Actor, ActorRef, ActorSelection, ActorSystem, Props}
import com.typesafe.config.ConfigFactory

object App {

  def main(args: Array[String]): Unit = {

    val WORKER_SYSTEM = "worker_system"
    val WORKER_ACTOR_SYSTEM = "worker_actor_system"

    val s: String =
      s"""
         |akka.actor.provider = "akka.remote.RemoteActorRefProvider"
         |akka.remote.netty.tcp.hostname = "127.0.0.1"
         |akka.remote.netty.tcp.port = 4444
      """.stripMargin

    val config = ConfigFactory.parseString(s)

    // 启动注册
    val workersystem = ActorSystem(WORKER_SYSTEM,config)
    val wactor: ActorRef = workersystem.actorOf(Props[Test],WORKER_ACTOR_SYSTEM)


  }

}
class Test extends Actor{

  override def preStart(): Unit = {

    val path = "akka.tcp://master_system@127.0.0.1:9999/user/master_actor_system"
    val selection: ActorSelection = context.actorSelection(path)
    println(selection)

    selection ! "hello "

  }

  override def receive: Receive = {
    case _=>println("wwwwwwwwwwwwwwww")
  }
}
